package comcksys.authserver.config;

import comcksys.authserver.config.convert.MyTokenStoreSerializationStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;

/**
 * token存储路径
 * @author: yxzhang23
 * @time: 2021/4/8
 */
@Configuration
public class AccessTokenConfig {

    private final RedisConnectionFactory redisConnectionFactory;

    @Autowired
    public AccessTokenConfig(RedisConnectionFactory redisConnectionFactory) {
        this.redisConnectionFactory = redisConnectionFactory;
    }

    @Bean
    TokenStore tokenStore() {
        RedisTokenStore redisTokenStore = new RedisTokenStore(redisConnectionFactory);
        redisTokenStore.setSerializationStrategy(new MyTokenStoreSerializationStrategy());
        return redisTokenStore;
    }

}
